package cn.com.game.link.utils;

import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.function.Consumer;

public class TextUtil {

	
	public static Consumer<Graphics> center(Rectangle hitbox, String text) {
		return g -> {
			FontMetrics fm = g.getFontMetrics();
			g.drawString(text, 
					hitbox.x + (hitbox.width - (int)fm.getStringBounds(text, g).getWidth()) / 2,
					hitbox.y + (hitbox.height - fm.getHeight()) / 2 + fm.getAscent()) ;
		};
	}
	
	
}
